<template>
  <el-col :span="6">
    <h5>图书分类</h5>
    <el-menu
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose" v-for="(item,index) in BookMenu" v-bind:key="index">
      <el-submenu :index=item.nameENG>
        <template slot="title">
        <i class="el-icon-location"></i>
        <span>{{item.nameCN}}</span>
        </template>
                <el-menu-item v-for="(subItem,index) in item.SubMenu" v-bind:key="index" @click.native="LinkTo(subItem.nameCN)">
                  <i class="el-icon-menu"></i>
                  <span slot="title">{{subItem.nameCN}}</span>
                </el-menu-item>
      </el-submenu>
    </el-menu>
  </el-col>
</template>

<script>
export default {
  name: 'Sidebar',
  data () {
    return {
      BookMenu: [
        {
          nameCN: '教育',
          nameENG: 'Education',
          SubMenu: [
            {
              nameCN: '教材',
              nameENG: 'EducationPaper'
            },
            {
              nameCN: '考试',
              nameENG: 'Examination'
            },
            {
              nameCN: '工具书',
              nameENG: 'ToolBook'
            }
          ]
        },
        {
          nameCN: '文艺',
          nameENG: 'LiteratureAndArt',
          SubMenu: [
            {
              nameCN: '文学',
              nameENG: 'Literature'
            },
            {
              nameCN: '传记',
              nameENG: 'Biography'
            },
            {
              nameCN: '艺术',
              nameENG: 'Art'
            }
          ]
        },
        {
          nameCN: '人文社科',
          nameENG: 'HumanitiesSocialSciences',
          SubMenu: [
            {
              nameCN: '历史',
              nameENG: 'History'
            },
            {
              nameCN: '文化',
              nameENG: 'Culture'
            }
          ]
        }
      ]
    }
  },
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    },
    LinkTo (url) {
      this.$router.push({
        path: '/Search',
        query: {
          class: url,
          from: 'sidebar'
        }
      })
      location.reload()
    }
  }
}
</script>

<style scoped>

</style>
